package com.liting.uitest.model;

import io.swagger.annotations.ApiModel;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 圆形
 */
@Data
@ApiModel(value = "圆形对象", description = "前端需要提交centerX、centerY、radius、name；name自定义 ，同一个image中不同模块的name不能相同")
public class Circle {
    private String name;
    private int centerX;
    private int centerY;
    private double radius;

    public BigDecimal getArea() {
        BigDecimal area = new BigDecimal(Math.PI * radius * radius).setScale(2, RoundingMode.UP);
        return area;
    }

    public boolean isInclude(int x, int y) {
        BigDecimal xDistance = new BigDecimal(x).subtract(new BigDecimal(centerX)).abs();
        BigDecimal yDistance = new BigDecimal(y).subtract(new BigDecimal(centerY)).abs();

        BigDecimal temp = xDistance.multiply(xDistance).add(yDistance.multiply(yDistance));

        double distance = Math.sqrt(temp.doubleValue());

        return (distance > radius) ? false : true;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj instanceof Circle) {
            Circle target = (Circle) obj;

            if (target.getRadius() == this.radius) {
                return true;
            } else {
                return false;
            }
        }

        return false;

    }
}
